<template>
	<view class="content">
		<!-- 头部信息 开始 -->
		<view class="person" v-if="userInfo.nickname!=null">
			<image :src="imgUrl+userInfo.avatar" mode=""></image>
			<view class="person_left">
				<view class="name display align-items">
					<text class="names ellipsis">{{userInfo.nickname}}</text>
					<text class="tj ellipsis" v-if="userInfo.parent_name">推荐人:{{userInfo.parent_name}}</text>
				</view>
				<view class="invite display align-items">
					<text class="yq">邀请码：{{userInfo.ucode}}</text>
					<text class="cop" @tap.stop="copy(userInfo.ucode)">复制</text>
				</view>
			</view>
			<view class="grade" @click="codeGrade">{{userInfo.grade_name}}</view>
		</view>
		<!-- 头部信息 结束 -->
		<!-- 通知 开始 -->
		<view class="inform" @click="brokerageTo">
			<view class="mony" v-if="userInfo.withdraw!=null" >
				{{userInfo.withdraw}}
			</view>
			<view class="mony" v-else>
				0
			</view>
			<view class="msg">
				成功提现佣金（元）
			</view>
		</view>
		<!-- 通知 结束 -->
		<!-- 分销详细 开始 -->
		<view class="person_list">
			<view class="list lists border_bottom_again" @click="commissionTo">
				<image class="img" src="../../static/icon/fx_money.png" mode=""></image>
				<view class="list_right">
					<view class="title">
						分销佣金
					</view>
					<view class="mony letter-spacing" v-if="userInfo.total_rebate!=null">
						{{userInfo.total_rebate}}元
					</view>
					<view class="mony letter-spacing" v-else>
						0元
					</view>
				</view>
			</view>
			<view class="list lists border_bottom_again" @click="levelAwardTo">
				<image class="img" src="../../static/icon/fx_money.png" mode=""></image>
				<view class="list_right">
					<view class="title">
						平级奖励
					</view>
					<view class="mony letter-spacing" v-if="userInfo.equal_rebate!=null">
						{{userInfo.equal_rebate}}元
					</view>
					<view class="mony letter-spacing" v-else>
						0元
					</view>
				</view>
			</view>
			<view class="list border_bottom_again"  @click="fxBtn">
				<image class="img" src="../../static/icon/fx_order.png" mode=""></image>
				<view class="list_right">
					<view class="title">
						分销订单
					</view>
					<view class="mony letter-spacing" v-if="userInfo.team_order!=null">
						{{userInfo.team_order}}笔
					</view>
					<view class="mony letter-spacing" v-else>
						0元
					</view>
				</view>
			</view>
			<view class="list border_bottom_again" @click="yjBtn">
				<image class="img" src="../../static/icon/fx_tdyj.png" mode=""></image>
				<view class="list_right">
					<view class="title">
						团队业绩
					</view>
					<view class="mony letter-spacing" v-if="userInfo.team_piece!=null">
						{{userInfo.team_piece}}单
					</view>
					<view class="mony letter-spacing" v-else>
						0单
					</view>
				</view>
			</view>
			<view class="list" @click="tdBtn">
				<image class="img" src="../../static/icon/fx_td.png" mode=""></image>
				<view class="list_right">
					<view class="title">
						我的团队
					</view>
					<view class="mony letter-spacing" v-if="userInfo.team_user!=null">
						{{userInfo.team_user}}人
					</view>
					<view class="mony letter-spacing" v-else>
						0人
					</view>
				</view>
			</view>
			<view class="list" @click="codeBtn">
				<image class="img" src="../../static/icon/fx_ewm.png" mode=""></image>
				<view class="list_right">
					<view class="title">
						二维码
					</view>
				</view>
			</view>
		</view>
		<!-- 分销详细 结束 -->
		<is-login v-on:childClick='listenToClose' v-on:childClickAgain='listenToCloseAgain' v-if="isLogin==0"></is-login>
	</view>
</template>

<script>
	import isLogin from '../../components/isLogin.vue'
	export default {
		data() {
			return {
				userInfo:{},
				isLogin: 1,
				imgUrl:null
			}
		},
		components: {
			isLogin,
		},
		onLoad() {
			this.imgUrl = this.$imgUrl
			
		},
		onShow() {
			if (!uni.getStorageSync('openid')) {
				this.isLogin = 0
			} else {
				this.isLogin = 1
				this.getUserInfo()
			}
		},
		onPullDownRefresh() {
			uni.showToast({
				icon: 'loading',
				title: '加载中',
			});
			setTimeout(() => {
				this.getUserInfo(() => {
					uni.hideLoading()
					uni.stopPullDownRefresh()
				})
			}, 1000)
		},
		methods: {
			// 获取个人信息
			getUserInfo(callback){
				let that = this
				var data = {
					openid: uni.getStorageSync('openid'),
				}
				this.$myRequest.post(this.$api.distribution.index, data).then(res => {
					if (res.code == '200') {
						that.userInfo = res.data.data
						callback && callback()
					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						})
					}
				})
			},
			// 平级奖励
			levelAwardTo(){
				if (!uni.getStorageSync('openid')) {
					uni.showToast({
						title: '请先登录',
						icon: "none"
					})
				} else {
					uni.navigateTo({
						url: "levelAward/levelAward"
					})
				}
			},
			// 佣金明细
			commissionTo() {
				if (!uni.getStorageSync('openid')) {
					uni.showToast({
						title: '请先登录',
						icon: "none"
					})
				} else {
					uni.navigateTo({
						url: "commission/commission"
					})
				}
				
			},
			// 提现
			brokerageTo() {
				if (!uni.getStorageSync('openid')) {
					uni.showToast({
						title: '请先登录',
						icon: "none"
					})
				} else {
					uni.navigateTo({
						url: "brokerage/index"
					})
				}
				
			},
			// 跳转分销订单页面
			fxBtn() {
				if (!uni.getStorageSync('openid')) {
					uni.showToast({
						title: '请先登录',
						icon: "none"
					})
				} else {
					uni.navigateTo({
						url: "orderForm/index"
					})
				}
				
			},
			// 跳转团队业绩页面
			yjBtn() {
				if (!uni.getStorageSync('openid')) {
					uni.showToast({
						title: '请先登录',
						icon: "none"
					})
				} else {
					uni.navigateTo({
						url: "performance/index"
					})
				}
			
			},
			// 跳转我的团队页面
			tdBtn() {
				if (!uni.getStorageSync('openid')) {
					uni.showToast({
						title: '请先登录',
						icon: "none"
					})
				} else {
					uni.navigateTo({
						url: "team/index"
					})
				}
				
			},
			// 跳转二维码页面
			codeBtn() {
				if (!uni.getStorageSync('openid')) {
					uni.showToast({
						title: '请先登录',
						icon: "none"
					})
				} else {
					uni.navigateTo({
						url: "QRcode/index"
					})
				}
				
			},
			// 跳转等级页面
			codeGrade() {
				if (!uni.getStorageSync('openid')) {
					uni.showToast({
						title: '请先登录',
						icon: "none"
					})
				} else {
					uni.navigateTo({
						url: "grade/grade"
					})
				}
				
			},
			copy: function(value) {
				uni.setClipboardData({
					data: value, // 要复制的文字
					success: function(res) {
						uni.getClipboardData({
							success: function(res) {
								uni.showToast({
									title: '复制成功'
								});
							}
						});
					}
				});
			},
			listenToClose(msg) {
				this.isLogin = msg
			},
			listenToCloseAgain() {
				this.getUserInfo()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 690rpx;
		margin: 0 auto;

		.person {
			height: 110rpx;
			width: 100%;
			display: flex;
			margin: 36rpx 0;
			position: relative;

			.grade {
				position: absolute;
				right: -30rpx;
				top: 0;
				bottom: 0;
				margin: auto;
				width: 113rpx;
				height: 46rpx;
				background: #4b968d;
				border-radius: 23rpx 0 0 23rpx;
				text-align: center;
				line-height: 46rpx;
				color: #FFFFFF;
				font-size: 22rpx;

			}

			image {
				width: 110rpx;
				height: 110rpx;
				border-radius: 100%;
				margin-right: 30rpx;
			}

			.person_left {
				.name {
					margin-top: 10rpx;

					.names {
						max-width: 200rpx;
						// display: inline-block;
						font-size: 34rpx;
						font-family: Source Han Sans CN;
						font-weight: 400;
						color: #333333;
						padding-right: 20rpx;
					}
					
					.tj {
						max-width: 200rpx;
						padding: 3rpx 15rpx;
						text-align: center;
						font-size: 18rpx;
						line-height: 35rpx;
						background: #F7DBC6;
						border-radius: 14rpx;
						color: #AC6E40;
					}
				}

				.invite {
					margin-top: 8rpx;
					.yq {
						// width: 160rpx;
						height: 24rpx;
						font-size: 26rpx;
						font-family: Source Han Sans CN;
						font-weight: 400;
						color: #666666;
						line-height: 30rpx;
					}

					.cop {
						width: 60rpx;
						// padding: 1px 0;
						// height: 26rpx;
						border: 1px solid #666666;
						border-radius: 13rpx;
						display: inline-block;
						color: #666666;
						// line-height: 26rpx;
						font-size: 18rpx;
						text-align: center;
						margin-left: 20rpx;
					}
				}
			}
		}

		.inform {
			margin: 41rpx 0;
			background: #FFFFFF;
			box-shadow: 0rpx 2rpx 10rpx 0rpx rgba(90, 96, 105, 0.14);
			border-radius: 10rpx;
			.mony {
				padding: 20rpx 0 10rpx 22rpx;
				font-size: 32rpx;
				font-family: Source Han Sans CN;
				font-weight: bold;
				color: #294D7C;
			}

			.msg {
				margin-left: 22rpx;
				font-size: 22rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #333333;
				padding-bottom: 25rpx;
			}
		}

		.person_list {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			background: #FFFFFF;
			box-shadow: 0px 2rpx 10rpx 0px rgba(90, 96, 105, 0.14);
			border-radius: 10rpx;
			background: #E5E5E5;
			overflow: hidden;

			.list {
				// margin: 1rpx 0;
				width: 345rpx;
				display: flex;
				align-items: center;
				background: #fff;
				height: 156rpx;
				// border: 1rpx solid #ccc;
				.img {
					width: 40rpx;
					height: 40rpx;
					margin-right: 20rpx;
					margin-left: 25rpx;
				}

				.list_right {
					.title {
						line-height: 30rpx;
						font-size: 26rpx;
						font-family: Source Han Sans CN;
						font-weight: 400;
						color: #333333;
					}
					.mony {

						font-size: 20rpx;
						font-family: Source Han Sans CN;
						font-weight: 400;
						color: #666666;
						margin-top: 5rpx;
					}
				}
			}

			.lists {
				margin: 0;
			}
		}
		.border_right{
			border: 1rpx solid #E5E5E5
		}
		.border_bottom_again{
			border-bottom: 1rpx solid #E5E5E5
		}
	}
</style>
